<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>Insert title here</title>
</head>
<body>
	<fieldset id="">
		<legend>设置部门</legend>
		<div class="layui-field-box">
			<form action="" class="layui-form layui-form-pane" lay-filter="formA"
				method="post">
				<div class="layui-form-item">
					<label class="layui-form-label">员工编号</label>
					<div id="" class="layui-input-inline">
						<input type="text" name="code" id="" readonly class="layui-input"
							lay-verify="required" placeholder="请输入编号" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">员工姓名</label>
					<div id="" class="layui-input-inline">
						<input type="text" name="name" id="" readonly class="layui-input"
							lay-verify="required" placeholder="请输入姓名" />
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">部门编号</label>
					<div id="" class="layui-input-inline">
						<select name="codeDept" id = "setDept">
							
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<div id="" class="layui-input-inline">
						<input type="button" name="" id="" value="确定" class="layui-btn"
							lay-submit lay-filter="setDept" /> <input type="button" name=""
							id="" value="取消" onclick="closeThis()" class="layui-btn " />
						<!-- 						<input type="reset" name="" id="" value="重置" class="layui-btn layui-btn-primary" /> -->
					</div>

				</div>
				<input type="hidden" name="action" id="" value="setDept" />
			</form>
		</div>

	</fieldset>
	<script type="text/javascript">
		initSelect();
		function initSelect(){
			ajax("/DepartmentServlet",{action:"list"},"json",function(data){
// 				console.log(data)

				///request 
				var option = "";
				$.each(data,function(){
					option += "<option value='"+this.code+"' >"+this.name+"</option>" 
				})
				$("select[id='setDept']").html(option);
				form.render();
				init();//Ajax请求的先后顺序，重点！
			})
		}
	
		var code = '<%=request.getParameter("code")%>'
		
		function init(){
			ajax("/employee",{action:"get",code:code},"json",function(aaa){
				console.log(aaa.codeDept)
				form.val("formA",{code:aaa.code,name:aaa.name,codeDept:aaa.codeDept})
			})
		}
		formSubmit("/employee","submit(setDept)","text",function(data){
			if(data==1){
				layer.msg("设置成功",closeThis)
			}else{
				layer.msg("设置失败")
			}
		})
	</script>
	
</body>
</html>